#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2021-11-26 17:38
# @Author : huabao.tan
# @File : selenium_key.py
# @Software: PyCharm
from time import sleep
from selenium import webdriver
#创建浏览器对象：给予需求创建对应的浏览器对象
def open_browser(txt):
    try:
        driver = getattr(webdriver, txt)()

    except Exception as e:
        print(e)
        driver = webdriver.Chrome()
    return driver

class Key:
    def __init__(self, txt):
        self.driver = open_browser(txt)

    def max(self):
        self.driver.maximize_window()
    #访问URL
    def open(self, url):
        self.driver.get(url)

    #查找元素
    def locator(self, txt):
        return self.driver.find_element_by_xpath(txt)

    #输入
    def input(self, txt, txt1):
        self.locator(txt).send_keys(txt1)

    #点击
    def click(self, txt):
        self.locator(txt).click()

    #等待
    def wait(self, time_):
        sleep(time_)

    #鼠标向下滚动
    def roll_max(self, txt):
        js = ("var q=document.documentElement.scrollTop='%s'".format(txt))
        self.driver.execute_script(js)
        self.wait(3)

    #切换表单
    def switch(self, txt):
        self.driver.switch_to.frame(txt)



    #等待
    def quint(self):
        self.driver.quit()





